#include <iostream>
#include <string.h>

using namespace std;

typedef char elemtype;

struct Node
{
    Node *lchild;
    Node *rchild;
    char value;
}Tree[50];

int loc=0;
Node *create()
{
    Tree[loc].lchild = Tree[loc].rchild = NULL;
    return &Tree[loc++];
}

void post(Node *T)
{
    if (NULL == T)
    {
        return ;
    }

    if (NULL != T->lchild)
    {
        post(T->lchild);
    }
    if (NULL != T->rchild)
    {
        post(T->rchild);
    }

    cout << T->value << " ";
}

char str1[] = "FDXEAG";
char str2[] = "XDEFAG";

Node* build(int s1, int e1, int s2, int e2)
{
    Node *p = create();
    p->value = str1[s1];

    int i;
    for (i = s2; i != e2; ++i)
    {
        if (str1[s1] == str2[i])
        {
            break;
        }
    }

    if (i != s2)
    {
        p->lchild = build(s1+1,s1+i-s2,s2,i-1);
    }
    if (i != e2)
    {
        p->rchild = build(s1+i-s2+1,e1,i+1,e2);
    }

    return p;
}

Node *insert(Node *T, int x)
{
    if (NULL == T)
    {
        T = create();
        T->value = x;
        return T;
    }
    else if (x<T->value)
    {
        T->lchild = insert(T->lchild, x);
    }
    else if (x>T->value)
    {
        T->rchild = insert(T->rchild, x);
    }

    return T;
}

int main()
{
//    Node *p = build(0, 6, 0, 6);
//    post(p);
    return 0;
}

